home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
graphic
/
dbwrendr.zip
/
SOURCE
/
RAY.H
< prev
next >
Wrap
Text File
|
1989-10-31
|
18KB
|
654 lines
/************************************************************************
* *
* Copyright (c) 1987, David B. Wecker *
* All Rights Reserved *
* *
* This file is part of DBW_Render *
* *
* DBW_Render is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY. No author or distributor accepts *
* responsibility to anyone for the consequences of using it or for *
* whether it serves any particular purpose or works at all, unless *
* he says so in writing. Refer to the DBW_Render General Public *
* License for full details. *
* *
* Everyone is granted permission to copy, modify and redistribute *
* DBW_Render, but only under the conditions described in the *
* DBW_Render General Public License. A copy of this license is *
* supposed to have been given to you along with DBW_Render so you *
* can know your rights and responsibilities. It should be in a file *
* named COPYING. Among other things, the copyright notice and this *
* notice must be preserved on all copies. *
************************************************************************
* *
* Authors: *
* DBW - David B. Wecker *
* jhl - John H. Lowery (IBM conversion) *
* *
* Versions: *
* V1.0 870125 DBW - First released version *
* V1.01 880918 jhl - ported to IBM PC (MCGA/VGA display hardware) *
* 890121 jhl - MAXROW & MAXCOL become variables, add *
* 'D' command for Display max <hor> <vert> *
* *
************************************************************************/
#define IBM_PC 1 /* V1.01 */
#include <math.h>
#include <stdio.h>
#include <setjmp.h>
#ifdef IBM_PC
#include <malloc.h>
#endif
#define VERSION "RAY v1.02 891031 (IBM PC/XT/AT)\n Copyright (C) 1989 J. Lowery and D. Wecker - all rights reserved\n"
#define pi 3.141592654
#define X 0
#define Y 1
#define Z 2
#define W 3
#define B 0
#define G 1
#define R 2
#define minimum( a, b ) ( ((a) < (b)) ? (a) : (b) )
#define maximum( a, b ) ( ((a) > (b)) ? (a) : (b) )
typedef float vector[3];
typedef float matrix[4][4];
typedef struct
{
float xmin, xmax;
float ymin, ymax;
}
window;
#define setwindow( xmin, ymin, xmax, ymax, w ) {\
w.xmin = xmin;\
w.ymin = ymin;\
w.xmax = xmax;\
w.ymax = ymax; }
#define copywindow( f, w ) {\
w.xmin = f.xmin;\
w.ymin = f.ymin;\
w.xmax = f.xmax;\
w.ymax = f.ymax; }
typedef struct
{
float xmin, xmax;
float ymin, ymax;
float zmin, zmax;
}
volume;
#define setvolume( xmin, ymin, zmin, xmax, ymax, zmax, v ) {\
v.xmin = xmin;\
v.ymin = ymin;\
v.zmin = zmin;\
v.xmax = xmax;\
v.ymax = ymax;\
v.zmax = zmax; }
#define copyvolume( f, v ) {\
v.xmin = f.xmin;\
v.ymin = f.ymin;\
v.zmin = f.zmin;\
v.xmax = f.xmax;\
v.ymax = f.ymax;\
v.zmax = f.zmax; }
typedef struct
{
vector vrp, vpn, vup, cop;
volume vol;
}
perspective_projection;
typedef struct
{
int tex;
float fuz, ref, idx;
vector tra, amb, dif;
}
attributes;
typedef struct
{
vector p;
float g;
int s;
}
fracvert;
#define CV(x,y,z,v) v[0]=(x); v[1]=(y); v[2]=(z)
#define VECZERO(v) v[0] = 0.0; v[1] = 0.0; v[2] = 0.0
#define VECCOPY(frm,to) to[0] = frm[0]; to[1] = frm[1]; to[2] = frm[2]
#define VECDUMP(v,str) printf("%s\t%5.3f %5.3f %5.3f\n",str,v[0],v[1],v[2])
#define VECSUB(v1,v2,r) r[0] = v1[0] - v2[0]; r[1] = v1[1] - v2[1];\
r[2] = v1[2] - v2[2]
#define VECSUM(v1,v2,r) r[0] = v1[0] + v2[0]; r[1] = v1[1] + v2[1];\
r[2] = v1[2] + v2[2]
#define VECMUL(v1,v2,r) r[0] = v1[0] * v2[0]; r[1] = v1[1] * v2[1];\
r[2] = v1[2] * v2[2]
#define VECDIV(v1,v2,r) r[0] = v1[0] / v2[0]; r[1] = v1[1] / v2[1];\
r[2] = v1[2] / v2[2]
#define VECSCALE(s,v,r) r[0] = (s)*v[0]; r[1] = (s)*v[1]; r[2] = (s)*v[2]
#define NORM(v) ((float)sqrt((v[0]*v[0])+(v[1]*v[1])+(v[2]*v[2])))
#define DOT(v1,v2) ((v1[0]*v2[0])+(v1[1]*v2[1])+(v1[2]*v2[2]))
#define CROSS(v1,v2,r) r[0] = (v1[1] * v2[2]) - (v2[1] * v1[2]);\
r[1] = (v1[2] * v2[0]) - (v2[2] * v1[0]);\
r[2] = (v1[0] * v2[1]) - (v2[0] * v1[1])
#define DIRECTION(f,t,d) VECSUB(t,f,d); normalize(d)
#define SPHERENORMAL(cent,p,n) DIRECTION(cent,p,n);
#define PLANENORMAL(ve,vp,n) CROSS(vp,ve,n); normalize(n);
#define ERROR( str ) { fprintf( stderr, "%s\n", str ); exit(0); }
#ifndef IBM_PC
extern char *malloc();
#endif
extern long time();
#define CHECK_ALLOC( ptr, typ ) {\
if (!(ptr = (typ *) malloc( sizeof( typ )))) {\
ERROR( "MALLOC - out of memory" ); \
exit( 0 ); \
} \
}
#define CHECK_ALLOCA( ptr, typ, num ) {\
if (!(ptr = (typ *) malloc( sizeof( typ ) * num ))) {\
ERROR( "MALLOC - out of memory" ); \
exit( 0 ); \
} \
}
#define sptr( p ) ((sphere *) p)
#define tptr( p ) ((triangle *) p)
#define qptr( p ) ((quad *) p)
#define rptr( p ) ((ring *) p)
#define eptr( p ) ((extent *) p)
#define cptr( p ) ((cylinder *) p)
#define EXTENT 0
#define SPHERE 1
#define TRIANGLE 2
#define QUAD 3
#define RING 4
#define CYLINDER 5
typedef float hvector[4];
typedef struct NODE
{
struct NODE *next;
int kind;
attributes attr;
}
node;
typedef struct
{
node *next;
int kind;
attributes attr;
vector position, ve, vp;
}
quad;
typedef struct
{
node *next;
int kind;
attributes attr;
vector position, ve, vp;
}
triangle;
typedef struct
{
node *next;
int kind;
attributes attr;
vector position, ve, vp;
float minrad, maxrad;
}
ring;
typedef struct
{
node *next;
int kind;
attributes attr;
vector center;
float radius;
}
sphere;
typedef struct
{
node *next;
int kind;
attributes attr;
vector bottom, top;
float a, b, c;
}
cylinder;
typedef struct
{
node *next;
int kind;
attributes attr;
vector base, apex;
float baserad;
}
cone;
typedef struct
{
node *next;
int kind;
attributes attr;
vector center;
float radius;
node *sub;
}
extent;
typedef struct
{
vector intensity;
vector direction;
float distscale, radius;
int kind;
}
lighttype;
typedef struct
{
vector center;
float wavelength, amplitude, drag, propagate;
}
wavetype;
typedef struct
{
vector color;
float distscale;
}
hazetype;
typedef struct
{
vector color;
float start, scale;
}
blendtype;
typedef struct
{
float start, altscale, altfactor, threshhold;
}
snowtype;
typedef struct
{
float scale, zoom;
}
pebbletype;
typedef struct
{
int level;
float xscale, yscale, zscale;
int texture;
}
fractaltype;
typedef struct
{
vector color;
float x, y, z, bevel, angle;